﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GTA.ExceptionHandling;

namespace GTA
{
    public partial class FrmErrorMessage : BaseForm
    {
        #region Local Objects
        private String Operation;
        private Exception Ex;
        private bool detailed = false;
        #endregion

        #region Start Form
        public FrmErrorMessage(String operation, Exception ex)
        {
            InitializeComponent();
            this.Operation = operation;
            this.Ex = ex;
        }
        private void FrmErrorMessage_Load(object sender, EventArgs e)
        {
            BuildMessageDetail();
        }
        #endregion

        #region Events
        private void cmdShowDetail_Click(object sender, EventArgs e)
        {
            ShowErrorDetail();
            cmdShowDetail.Focus();
        }
        #endregion

        #region Methods
        private void BuildMessageDetail()
        {
            lblOperationName.Text = Operation;
            if (Ex is BusinessException)
            {
                txtErrorMessage.Text = ((BusinessException)Ex).Message;
                txtErrorDetail.Text = ((BusinessException)Ex).MessageFull;
            }
            else if (Ex is ValidationException)
            {
                txtErrorMessage.Text = ((ValidationException)Ex).Message;
                txtErrorDetail.Text = ((ValidationException)Ex).MessageFull;
            }
            else
            {
                txtErrorMessage.Text = Ex.Message;
                txtErrorDetail.Text = Common.Util.GetFullException(Ex);
            }
        }
        private void ShowErrorDetail()
        {
            if (!detailed)
            {
                this.Size = new Size(617, 455);
                detailed = true;
            }
            else
            {
                detailed = false;
                this.Size = new Size(617, 259);
            }
        }
        #endregion
    }
}
